from typing import Union
from fastapi import FastAPI
from dotenv import load_dotenv
from sqlmodel import SQLModel

from app.api.router import router

app = FastAPI()

app.include_router(router)

if __name__ == "__main__":
    from settings import env_settings

    print(env_settings.database_url)
    print(env_settings.need_mysql_init)
    if  env_settings.need_mysql_init:
        from app.api.database.base import db_service
        from app.api.database.models import *
        print(f"开始创建数据库,tables={SQLModel.metadata.tables}")
        SQLModel.metadata.create_all(db_service.engine)  # 自动创建所有定义的表


    import uvicorn

    uvicorn.run("main:app", host="localhost", port=8000)
